// my/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrls: [
      'https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640',
      'https://images.unsplash.com/photo-1551214012-84f95e060dee?w=640',
      'https://images.unsplash.com/photo-1551446591-142875a901a1?w=640'
    ],
    indicatorColor: 'white',
    indicatorActivecolor: 'red',
    msgList: [{
        url: "url",
        title: "[6月7日 14：25]温水发布了消息"
      },
      {
        url: "url",
        title: "[6月8日 14：25]尔非尔发布了消息"
      },
      {
        url: "url",
        title: "[6月9日 14：25]铁塔发布了消息"
      }
    ],
    ani_1: null,
    ani_2: null,
    ani_3: null,
    ani_4: null,
    ani_5: null,
    isFixed: false,
    opacity: 0,
    sacle: 0.2,
    message: [],
    ershou: '二手闲置',
    pinche: '拼车出行',
    tucao: '心事吐槽',
    biaobai: '表白勾搭',
    wenda: '友情问答',
    messageLength: '',
    isBtm: false,
    isIpt: false,
    iptVal: [],
    mes: {},
  },
  // 评论
  iptVal(e) {
    var iptVal = e.detail.value;
    console.log(iptVal)
    console.log(this.data.mes.ipt)
    var iptVal = iptVal + ',' + this.data.mes.ipt
    this.setData({
      iptVal: iptVal,
    })
  },
  test() {
    var db = wx.cloud.database();
    db.collection('dxd_get').doc(this.data.mes._id).update({
      // data 传入需要局部更新的数据
      data: {
        ipt: this.data.iptVal
      },
      success: (res) => {
        wx.showToast({
          title: '上传成功',
          duration: 1500
        })
        this.setData({
          isIpt: false
        })
        this.getdata()
      },
      error: a => {
        wx.showToast({
          title: '上传失败',
          duration: 1500
        })
        this.setData({
          isIpt: false
        })
      }
    })

  },
  isIpt(e) {
    this.setData({
      isIpt: true,
      mes: e.currentTarget.dataset.mes
    })
  },
  hide() {
    this.setData({
      isIpt: false
    })
  },
  // 5type
  ershou(e) {
    var type = e.currentTarget.dataset.type;
    wx.setStorage({
      key: 'dxd_type',
      data: type,
      success: function(res) {
        wx.navigateTo({
          url: '/shouY/xiangQ5/xiangQ5',
        })
      },
    })
  },
  pinche(e) {
    var type = e.currentTarget.dataset.type;
    wx.setStorage({
      key: 'dxd_type',
      data: type,
      success: function(res) {
        wx.navigateTo({
          url: '/shouY/xiangQ5/xiangQ5',
        })
      },
    })
  },
  tucao(e) {
    var type = e.currentTarget.dataset.type;
    wx.setStorage({
      key: 'dxd_type',
      data: type,
      success: function(res) {
        wx.navigateTo({
          url: '/shouY/xiangQ5/xiangQ5',
        })
      },
    })
  },
  biaobai(e) {
    var type = e.currentTarget.dataset.type;
    wx.setStorage({
      key: 'dxd_type',
      data: type,
      success: function(res) {
        wx.navigateTo({
          url: '/shouY/xiangQ5/xiangQ5',
        })
      },
    })
  },
  wenda(e) {
    var type = e.currentTarget.dataset.type;
    wx.setStorage({
      key: 'dxd_type',
      data: type,
      success: function(res) {
        wx.navigateTo({
          url: '/shouY/xiangQ5/xiangQ5',
        })
      },
    })
  },
  // 数据获取
  getdata() {
    const db = wx.cloud.database()
    db.collection('dxd_get').orderBy('date', 'desc').get({
      success: (res) => {
        console.log(res)
        // for (var i = 0; i < res.data.length; i++) {
        //   res.data[i].ipt = res.data[i].ipt.split(',')
        //   console.log(res.data[i].ipt)
        // }
        this.setData({
          message: res.data,
        })


        db.collection('dxd_get').count().then(res => {
          this.setData({
            messageLength: res.total
          })
          if (this.data.messageLength == this.data.message.length) {
            this.setData({
              isBtm: true
            })
          }

        })
      },
    })
  },

  // 刷新
  shuaX() {
    console.log(this.data.allPlun)
    wx.showLoading({
      title: '正在刷新...',
    })
    this.getdata()
    wx.hideLoading()
  },
  //发布
  faBuFun() {
    wx.navigateTo({
      url: '/shouY/fabu/fabu',
    })
  },
  onGotUserInfo: function(e) {
    var my = {
      title: e.detail.userInfo.nickName,
      url: e.detail.userInfo.avatarUrl
    }
    wx.setStorage({
      key: 'my',
      data: my,
      success: () => {
        wx.navigateTo({
          url: '/shouY/fabu/fabu',
        })
      }
    })

  },



  // 动画未完成
  animate() {
    var step = {
      duration: 500
    }
    var animation = wx.createAnimation();
    var animation1 = animation.rotate(180).step(step).scale(this.data.sacle).step(step).opacity(this.data.opacity).step(step),
      animation = wx.createAnimation({}),
      animation5 = animation.rotate(180).step(step).opacity(1).step(step)
    if (this.data.isFixed == true) {
      var animation = wx.createAnimation(),
        animation6 = animation.rotate(360).step(step),
        animation = wx.createAnimation(),
        animation2 = animation.rotate(-360).step(step).scale(1).step(step).opacity(1).step(step);
      this.setData({
        ani_1: animation2,
        ani_2: animation2,
        ani_3: animation2,
        ani_4: animation2,
        ani_5: animation6,
      })
    } else {
      this.setData({
        opacity: 0,
        scale: 0.2,
        ani_1: animation1,
        ani_2: animation1,
        ani_3: animation1,
        ani_4: animation1,
        ani_5: animation5,
      })
    }
    this.setData({
      opacity: 0,
      scale: 0.2,
      isFixed: !this.data.isFixed,
      ani_1: null,
      ani_2: null,
      ani_3: null,
      ani_4: null,
      ani_5: null,
    })
  },
  phoneMe() {
    wx.makePhoneCall({
      phoneNumber: '17695443146',
      success: res => {
        console.log(res)
      }
    })
  },
  phone(e) {
    let phone = e.currentTarget.dataset.phone.tele
    if (phone == '') {
      wx.showToast({
        title: '该用户没有保存电话号码',
        icon: 'none',
        duration: 1500
      })
    }
    wx.makePhoneCall({
      phoneNumber: phone,
      success: res => {
        console.log(res)
      }
    })
  },
  // 发布详情
  xiangQ_Fun(e) {
    console.log(e)
    let xiangQ = e.currentTarget.dataset.message;
    wx.setStorage({
      key: 'shouY_xiangQ',
      data: xiangQ,
      success: res => {
        wx.navigateTo({
          url: '../../shouY/XQ/XQ',
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function() {},


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getdata();
  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})